import { createRouter,createWebHistory } from "vue-router";
import HomeView from '@/pages/HomeView.vue'
import LoginView from '@/pages/LoginView.vue'
import { routerChildrens } from "./navBar";//子导航

const routes = [
  // // 当页面不存在时，跳到404页面
  //   {
	// 	path: '/:catchAll(.*)',
	// 	hidden: true,
	// 	component: () => import('@/pages/404.vue'),//这个是我自己的路径
	// },
    {
        path:'/home',
        name:'home',
        // component:()=>import('@/pages/HomeView.vue')
        component:HomeView,
        children:routerChildrens

    },
    {
        path:'/login',
        name:'login',
        // component:()=>import('@/pages/LoginView.vue')
        component:LoginView
    },
]

const router = createRouter({
    history: createWebHistory(),
    routes
})
import Cookies from "js-cookie";

// 路由首位
router.beforeEach((to,from,next)=>{
    let username = Cookies.get('username');//这里根据自己项目的实际情况添加是否登录的判断条件
    if (to.name !== 'login' && !username) next({ name: 'login',query: { redirect: to.fullPath }})
    else next()
  })
export default router
